var limsLocationBoard = Gikam.getPageObject({

    getBoardHoleParamFields : function(){
        return[{
            field : 'param1',
            title : '参数1'
        },{
            field : 'param2',
            title : '参数2'
        }]
    },

    getSquareEditListColumns : function(){
        return [{
            checkbox: true
        },{index: true}, {
            field: 'boardCode',
            title: 'T_LIMS_LOCATION_BOARD.BOARDCODE'
        }, {
            field: 'boardName',
            title: 'T_LIMS_LOCATION_BOARD.BOARDNAME',
            validators : ['strLength[0,30]'],
            editor: true
        }, {
            field: 'boardType',
            title: 'T_LIMS_LOCATION_BOARD.BOARDTYPE',
            type: 'select',
            category: 'sys',
            firstBlank: false,
            editor: true,
            param: {
                codeCategoryId: 'boardType'
            },
        }, {
            field: 'ext$.samplecount',
            title: 'T_LIMS_LOCATION_BOARD.SAMPLECOUNT',
        }, {
            field: 'rowNum',
            title: 'T_LIMS_LOCATION_BOARD.ROWNUM',
        }, {
            field: 'columnNum',
            title: 'T_LIMS_LOCATION_BOARD.COLUMNNUM',
        }, {
            field: 'freeHoleCount',
            title: 'T_LIMS_LOCATION_BOARD.FREEHOLECOUNT',
        }, {
            field: 'ext$.locationdesc',
            title: 'LIMS.TAB.LOCATION.BOARD'
        }]
    },

    getEditListColumns: function () {
        return [{
            checkbox: true
        },{index: true}, {
            field: 'boardCode',
            title: 'T_LIMS_LOCATION_BOARD.BOARDCODE',
            type: 'link'
        }, {
            field: 'boardName',
            title: 'T_LIMS_LOCATION_BOARD.BOARDNAME',
            validators : ['strLength[0,30]'],
            editor: true
        }, {
            field: 'boardType',
            title: 'T_LIMS_LOCATION_BOARD.BOARDTYPE',
            type: 'select',
            category: 'sys',
            firstBlank: false,
            editor: true,
            param: {
                codeCategoryId: 'boardType'
            },
        }, {
            field: 'ext$.samplecount',
            title: 'T_LIMS_LOCATION_BOARD.SAMPLECOUNT',
        }, {
            field: 'rowNum',
            title: 'T_LIMS_LOCATION_BOARD.ROWNUM',
        }, {
            field: 'columnNum',
            title: 'T_LIMS_LOCATION_BOARD.COLUMNNUM',
        }, {
            field: 'freeHoleCount',
            title: 'T_LIMS_LOCATION_BOARD.FREEHOLECOUNT',
        }, {
            field: 'ext$.locationdesc',
            title: 'LIMS.TAB.LOCATION.BOARD'
        },];
    },

    getBaseInfoFormFields: function () {
        return [{
            field: 'boardCode',
            title: 'T_LIMS_LOCATION_BOARD.BOARDCODE',
            validators: [{
                type: 'unique',
                rule: '/secure/baseline/samplemanage/location-boards/action/validate-unique'
            }, 'notEmpty','strLength[0,33]'],
            preInsert: true
        }, {
            field: 'boardName',
            title: 'T_LIMS_LOCATION_BOARD.BOARDNAME',
            validators : ['strLength[0,30]'],
            preInsert: true
        }, {
            field: 'boardType',
            title: 'T_LIMS_LOCATION_BOARD.BOARDTYPE',
            type: 'select',
            category: 'sys',
            firstBlank: false,
            param: {
                codeCategoryId: 'boardType'
            },
            preInsert: true
        }, {
            field: 'rowNum',
            title: 'T_LIMS_LOCATION_BOARD.ROWNUM',
            validators: ['number', 'numRange(0, 100','strLength[0,2]'],
            preInsert: true
        }, {
            field: 'columnNum',
            title: 'T_LIMS_LOCATION_BOARD.COLUMNNUM',
            validators: ['number', 'numRange(0, 100','strLength[0,2]'],
            preInsert: true
        }];
    },

    getHoleDetailInfoFormFields: function () {
        return [{
            field: 'sampleCode',
            title: 'T_LIMS_SAMPLE.SAMPLECODE',
        }, {
            field: 'sampleType',
            title: 'T_LIMS_SAMPLE.SAMPLETYPE',
        }, {
            field: 'sampleName',
            title: 'T_LIMS_SAMPLE.SAMPLENAME',
        }];
    },

    getStorageSampleListColumns: function () {
        return [{
            checkbox: true
        }, {
            index: true
        }, {
            field: 'sampleCode',
            title: 'T_LIMS_SAMPLE.SAMPLECODE',
            styleFormatter: function (row) {
            },
        }, {
            field: 'locations',
            title: 'T_LIMS_SAMPLE.LOCATIONS2',
            editor: true,
            type: 'choose',
            category: 'board-choose',
            single: true,
            onBeforeChoose: function () {
                Gikam.alert('T_LIMS_LOCATION.TIP.NOT_CHOOSE');
                return false;
            },
            onClean: function (field, value, index) {
                var _this = this;
                let activedRow = this.getData()[index];
                workspace.window.showMask();
                Gikam.postText(limsLocationBoard.baseUrl + "/clean-samples", Gikam.getJsonWrapper({}, [null, [activedRow]])).done(function (data) {
                    _this.refreshRowById(activedRow.id);

                    var boardGrid = Gikam.getComp('lims-storage-location-board-choose-list-grid');
                    var sampleActivedRow = Gikam.getComp('lims-storage-location-board-sample-list-grid').getActivedRow();
                    var activedBoardRow = boardGrid.getActivedRow();
                    boardGrid.refreshRowById(activedBoardRow.id);
                    // 刷新板子
                    Gikam.postSync(limsLocationBoard.holeUrl + '/queries', Gikam.getJsonWrapper({
                        f: {
                            boardId_EQ: activedBoardRow.id
                        },
                        n: -1, s: -1
                    })).done(function (data) {
                        let row = data.rows.find(f => f.id == sampleActivedRow.boardHoleId);
                        const  iframeDom=document.querySelector("#ksh-storage-location-board-iframe >iframe");
                        iframeDom.contentWindow.postMessage({
                            type:2,
                            data: row
                        }, "*");
                    });
                }).always(function () {
                    workspace.window.closeMask();
                });
            },
            width: 140
        }, {
            field: 'ext$.batchcode',
            title: 'T_LIMS_BATCH.BATCHCODE',
            type: 'link',
            width: 140
        }, {
            field: 'receiveAbnormalType',
            title: 'T_LIMS_SAMPLE.RECEIVEABNOMALTYPE',
            type: 'select',
            firstBlank: false,
            multiple: true,
            category: 'sys',
            param: {
                codeCategoryId_EQ: 'receiveAbnormalType'
            },
        }, {
            field: 'collectTime',
            title: 'T_LIMS_SAMPLE.COLLECTTIME',
            preInsert: true,
            type: 'dateTime',
            width: 140
        }];
    },

    getSampleListColumns: function () {
        return [{
            checkbox: true
        }, {
            index: true
        }, {
            field: 'sampleCode',
            title: 'T_LIMS_SAMPLE.SAMPLECODE'
        }, {
            field: 'hissampleCode',
            title: 'T_LIMS_SAMPLE.HISSAMPLECODE'
        }, {
            field: 'locations',
            title: 'T_LIMS_SAMPLE.LOCATIONS2',
            editor: true,
            type: 'choose',
            category: 'board-choose',
            single: true,
            onBeforeChoose: function () {
                Gikam.alert('T_LIMS_LOCATION.TIP.NOT_CHOOSE');
                return false;
            },
            onClean: function (field, value, index) {
                let _this = this;
                let activedRow = this.getData()[index];
                workspace.window.showMask();
                Gikam.postText(limsLocationBoard.baseUrl + "/clean-samples", Gikam.getJsonWrapper({}, [null, [activedRow]])).done(function (data) {
                    _this.refreshRowById(activedRow.id)

                    var boardGrid = Gikam.getComp('lims-location-board-choose-list-grid');
                    var activedBoardRow = boardGrid.getActivedRow()
                    boardGrid.refreshRowById(activedBoardRow.id)
                    limsLocationBoard.refreshHole(activedBoardRow.id)
                }).always(function () {
                    workspace.window.closeMask();
                });
            },
            width: 140
        }, {
            field: 'ext$.batchcode',
            title: 'T_LIMS_BATCH.BATCHCODE',
            type: 'link',
            width: 140
        }, {
            field: 'expNumber',
            title: 'T_LIMS_SAMPLE.EXPNUMBER',
            width: 140
        }, {
            field: 'receiveAbnormalType',
            title: 'T_LIMS_SAMPLE.RECEIVEABNOMALTYPE',
            type: 'select',
            firstBlank: false,
            multiple: true,
            category: 'sys',
            param: {
                codeCategoryId_EQ : 'receiveAbnormalType'
            }
        }, {
            field: 'collectTime',
            title: 'T_LIMS_SAMPLE.COLLECTTIME',
            preInsert: true,
            type: 'dateTime',
            width: 140
        }];
    },

    getSampleManageListColumns: function () {
        return [{
            checkbox: true
        }, {
            index: true
        }, {
            field: 'sampleCode',
            title: 'T_LIMS_SAMPLE.SAMPLECODE',
            styleFormatter: function (row) {
            },
        }, {
            field: 'hissampleCode',
            title: 'T_LIMS_SAMPLE.HISSAMPLECODE',
            width: 140
        }, {
            field: 'expNumber',
            title: 'T_LIMS_SAMPLE.EXPNUMBER',
            width: 140
        }, {
            field: 'locations',
            title: 'T_LIMS_SAMPLE.LOCATIONS2',
            editor: true,
            type: 'choose',
            category: 'board-choose',
            single: true,
            onBeforeChoose: function () {
                Gikam.alert('T_LIMS_LOCATION.TIP.NOT_CHOOSE');
                return false;
            },
            onClean: function (field, value, index) {
                let _this = this;
                let activedRow = this.getData()[index];
                workspace.window.showMask();
                Gikam.postText(limsLocationBoard.baseUrl + "/clean-samples", Gikam.getJsonWrapper({}, [null, [activedRow]])).done(function (data) {
                    _this.refreshRowById(activedRow.id)

                    var boardGrid = Gikam.getComp('lims-location-board-choose-list-grid');
                    var activedBoardRow = boardGrid.getActivedRow()
                    boardGrid.refreshRowById(activedBoardRow.id)
                    limsLocationBoard.refreshHole(activedBoardRow.id)
                }).always(function () {
                    workspace.window.closeMask();
                });
            },
            width: 140
        }, {
            field: 'receiveAbnormalType',
            title: 'T_LIMS_SAMPLE.RECEIVEABNOMALTYPE',
            type: 'select',
            firstBlank: false,
            multiple: true,
            category: 'sys',
            param: {
                codeCategoryId_EQ : 'receiveAbnormalType'
            }
        }];
    },

    refreshHole: function (id) {
        Gikam.postSync(limsLocationBoard.holeUrl + '/queries', Gikam.getJsonWrapper({
            f: {
                boardId_EQ: id
            },
            n: -1, s: -1
        })).done(function (data) {
            if (Gikam.isEmpty(data.rows)) {
                Gikam.getComp('sample-Location-choose').rowNum = 0;
            } else {
                Gikam.getComp('sample-Location-choose').setData(data.rows);
            }
        });
    },

    getChooseListColumns: function () {
        return [{index: true},{
            field: 'boardCode',
            title: 'T_LIMS_LOCATION_BOARD.BOARDCODE',
            width: 140
        }, {
            field: 'boardName',
            title: 'T_LIMS_LOCATION_BOARD.BOARDNAME',
            width: 140
        }, {
            field: 'freeHoleCount',
            title: 'T_LIMS_LOCATION_BOARD.FREEHOLECOUNT',
            width: 140
        }, {
            field: 'ext$.locationdesc',
            title: 'T_LIMS_LOCATION.LOCATIONDESC',
            width: 140
        }, {
            field: 'boardType',
            title: 'T_LIMS_LOCATION_BOARD.BOARDTYPE',
            type: 'select',
            category: 'sys',
            firstBlank: false,
            param: {
                codeCategoryId: 'boardType'
            },
            width: 140
        }, {
            field: 'rowNum',
            title: 'T_LIMS_LOCATION_BOARD.ROWNUM',
            width: 140
        }, {
            field: 'columnNum',
            title: 'T_LIMS_LOCATION_BOARD.COLUMNNUM',
            width: 140
        }];
    },

    getSelectInfoFormFields: function (treeId) {
        return [{
            field: 'locationDesc',
            title: 'T_LOCATION.BX',
            type: 'select',
            search: true,
            category: 'refrigeratorChoose',
            titleAlign: 'left',
            firstBlank: true,
            param: {
                parentId_EQ: 1,
            },
            onChange: function (field, value, ss) {
                let parent = 1;
                if(Gikam.isNotEmpty(value)){
                    parent = value
                }
                Gikam.getAsyncComp(treeId).done(function (grid) {
                    grid.refresh({
                        url : limsLocation.baseUrl + '/tree/' + parent,
                        createdByOrgId_EQ: workspace.user.ext$.loginorgid,
                    });
                });
                Gikam.getComp('sample-Location').setData([]);
            },
        }];
    },

    baseUrl: IFM_CONTEXT + '/secure/baseline/samplemanage/location-boards',
    sampleUrl: IFM_CONTEXT + '/secure/baseline/samplemanage/samples',
    holeUrl: IFM_CONTEXT + '/secure/baseline/samplemanage/location-board-holes',
    batchUrl: IFM_CONTEXT + '/secure/basemodule/business/batchs',

    loadBatchDetailPage: function (row) {
        Gikam.create('modal', {
            height: '90%',
            width: '90%',
            title: 'BASELINE.BUSINESS.BATCH.MODAL.DETAIL',
            url: limsLocationBoard.batchUrl + '/page/detail-top' + Gikam.param({
                id: row.ext$.batchid,
                topPage : '1'
            }),
        })
    },

    loadBatchDetailPageReadonlyWH: function (row) {
        workspace.window.load(limsLocationBoard.batchUrl + '/page/detail-top' + Gikam.param({
            id: row.ext$.batchid
        }))
    },

    loadKSHBoardHoleDetailPage: function (row) {
        workspace.window.load(limsLocationBoard.baseUrl + '/page/ksh/board-detail' + Gikam.param({
            id: row.id
        }))
    },

    loadSimpleBoardHoleDetailPage: function (row) {
        workspace.window.load(limsLocationBoard.baseUrl + '/page/simple/board-detail' + Gikam.param({
            id: row.id
        }))
    },
});
